//
//  BlockController.m
//  BlockTest
//
//  Created by 崔宝印 on 2017/12/7.
//  Copyright © 2017年 Koolearn. All rights reserved.
//

#import "StrongSelfBlockController.h"

@interface StrongSelfBlockController ()

@end

@implementation StrongSelfBlockController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.testName = @"123";
    
    __weak __typeof(self) weakSelf = self;
    self.testBlock = ^(void){
        __strong __typeof(weakSelf) strongSelf = weakSelf;//block的函数体会强引用self(局部变量)，函数执行完成后释放self，执行不完，self不会被释放
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            for (int i = 0; i < 30000; i++)
            {
                NSLog(@"%d:%@",i,strongSelf.testName);
            }
        });
    };
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.testBlock();
}

- (void)setTestWithController:(ViewController *)controller
{
    NSLog(@"%@",controller.testString);
    self.testString = controller.testString;
}

- (void)dealloc
{
    //block函数体没有执行完，controller不会释放
    NSLog(@"%s",__func__);
}



@end
